﻿namespace AppHtml.Control
{
    using System.Collections.Generic;
    using System.Linq;
    //
    using System.Text;
    using DbFrame.Class;

    public class KOViewModelControl
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="More"></param>
        /// <returns></returns>
        public StringBuilder ScriptStr(DbFrame.Class.BaseEntity Model, string[] More)
        {
            var sb = new StringBuilder();
            this.Get(Model, More, sb);
            return sb;

        }

        public StringBuilder ScriptStr(List<DbFrame.Class.BaseEntity> _Model_List, string[] More)
        {
            var sb = new StringBuilder();
            foreach (var item in _Model_List)
            {
                this.Get(item, More, sb);
            }
            return sb;
        }

        private StringBuilder Get(DbFrame.Class.BaseEntity Model, string[] More, StringBuilder sb)
        {
            ReflexHelper.GetPropertyInfos(Model.GetType()).ToList().ForEach(item =>
            {
                sb.Append("this." + item.Name + "=ko.observable('');");
            });

            if (More != null)
            {
                More.ToList().ForEach(item =>
                {
                    sb.Append("this." + item + "=ko.observable('');");
                });
            }
            return sb;
        }




    }
}